//策略模式

//策略接口：计算面积的抽象方法
class AreaCalculator
{
public:
	virtual double calculateArea(double param1, double param2) = 0;
};

//具体策略类
class TriangleAreaCalculator : public AreaCalculator
{
public:
	double calculateArea(double base, double height) const override
	{
		return 0.5 * base * height;
	}
};

class RectangleAreaCalculator : public AreaCalculator
{
public:
	double calculateArea(double length, double width) const override
	{
		return length * width;
	}
};

//上下文类
class Shape
{
private:
	AreaCalculator* areaCalculator;
public:
	Shape(AreaCalculator* calculator)
		:areaCalculator(calculator)
	{}
	double calculateShapeArea(double param1, double param2)
	{
		return areaCalculator->calculateArea(param1, param2);
	}

};